﻿$MET.Load.Install(function () {
//  //检测是否登录
//  if ($MCC.GetIndex("UserName") < 0 || $MCC.GetIndex("ChekKey") < 0) {
//      $MRT.Redirect("WebSite/Branch/Account/Login.html");
//      return;
//  }

    //显示界面
    $MEM("MainForm").Show();
    //拉取菜单信息
    var RTUrl = "Service/Basic/Menu/GetMainMenuHtml.ashx";
    var RTData = "Level=1"; //1为从级别1开始的菜单
    $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
        var Json = $MJO.GetObject(xmlData);
        if (Json != null && Json.Successful == true) {
            //用户凭证验证失败
            $MEM("Menu").innerHTML = Json.Data;
            /*显示隐藏主菜单 以及特效*/
            $("#Menu li").hover(function () {
                $(this).find("ul:first").slideDown(150);
            }, function () {
                $(this).find("ul:first").slideUp(1);
            });
        }
    });
    //获取所有系统模式信息
    RTUrl = "Service/Basic/Search/GetAllSystemMode.ashx";
    RTData = "";
    $MRT.Ajax(true, RTUrl, RTData, function (xmlData) {
        var Json = $MJO.GetObject(xmlData);
        if (Json != null && Json.Successful == true) {
            $MEM("SystemMode").options.length = 0;
            for (var I in Json.Data) {
                var Op = document.createElement("OPTION");
                Op.value = Json.Data[I].No;
                Op.text = Json.Data[I].TypeName;

                $MEM("SystemMode").add(Op);
            }
            //获取当前系统模式
            RTUrl = "Service/Basic/GetSystemMode.ashx";
            RTData = "";
            $MRT.Ajax(true, RTUrl, RTData, function (xmlData) {
                var Json = $MJO.GetObject(xmlData);
                if (Json != null && Json.Successful == true) {
                    $MEM("SystemMode").value = Json.Data;
                    $MEM("PageFrame").src = "./SourceOverview.html";
                    //$MEM("PageFrame").src = "WebSite/Branch/RealInformation/BaiduMapApi/BaiduMap.htm";
                }
            });
            //如果有超过一种系统模式则显示控件
            if (Json.Data.length > 1) {
                //设置系统模式移动特效
                $MEM("SystemMode").SetOpacity(60);
                $MEM("SystemMode").onmouseout = function () {
                    $MEM(this).SetOpacity(60);
                }
                $MEM("SystemMode").onmouseover = function () {
                    $MEM(this).FadeIn(10);
                }
                $MEM("SystemMode").Show();
            }
            else {
                $MEM("SystemMode").Hide();
            }
        }
    });
    //绑定选择系统事件
    $MEM("SystemMode").onchange = function () {
        var Mode = this.value;
        if (Mode >= 0) {
            var RTUrl = "Service/Basic/SetSystemMode.ashx";
            var RTData = "Mode=" + Mode;
            $MRT.Ajax(true, RTUrl, RTData, function (xmlData) {
                var Json = $MJO.GetObject(xmlData);
                if (Json != null && Json.Successful == true) {
                    //设置默认页
                    //$MEM("PageFrame").src = "WebSite/Branch/SourceInformation/SourceOverview.html";
                    $MEM("PageFrame").src = "WebSite/Branch/RealInformation/BaiduMapApi/BaiduMap.htm";
                }
                else {
                    $.messager.alert("提示", "切换系统失败,请重试.");
                }
            });
        }
        else {
            $.messager.alert("提示", "请选择正确的系统.");
        }
    }
    //每间隔8秒验证一次用户
    setInterval(function () {
        //刷新用户验证
        //RefreshChek();
        //刷新用户状态
        RefreshStatus();
    }, 8000);
    //刷新用户验证
    //RefreshChek();
    //刷新用户状态
    RefreshStatus();
    //载入样式框背景
    $MEM("Stage").style.backgroundImage = "url('../img/StageBg.jpg')"
});

/*刷新用户验证*/
function RefreshChek() {
    if ($MCC.GetValue("UserName") != null && $MCC.GetValue("ChekKey") != null) {
        var RTUrl = "Service/Basic/User/Beat.ashx";
        var RTData = "OnLineType=1"; //OnLineType为在线方式
        $MRT.Ajax(true, RTUrl, RTData, function (xmlData, state) {
            var Json = $MJO.GetObject(xmlData);
            if (Json != null && Json.Successful == false) {
                //用户凭证验证失败
                $.messager.alert("提示", "用户凭证过期,系统将在<label style='color:red;'>5秒</label>后返回登录界面.");
                setTimeout(function () {
                    $MCC.Clear();
                    $MRT.Redirect("WebSite/Branch/Account/Login.html");
                }, 6000);
            }
            else {

            }
        });
    }
    else {
        $MRT.Redirect("WebSite/Branch/Account/Login.html");
    }
}
/*刷新用户状态*/
function RefreshStatus() {
    //刷新用户状态
    var RTUrl = "Service/Basic/User/GetStatus.ashx";
    var RTData = "";
    $MRT.Ajax(true, RTUrl, RTData, function (xmlData) {
        var Json = $MJO.GetObject(xmlData);
        if (Json != null && Json.Successful == true) {
            var Data = Json.Data;
            //载入新消息数量
            var NewsSum = Data.NewsSum;
            if (NewsSum > 0) {
                $MEM("ImgNews").title = "您有" + NewsSum + "条信息,点击查看.";
                $MEM("ImgNews").src = "WebSite/Image/Ico/MailNew.png";
            }
            else {
                $MEM("ImgNews").title = "";
                $MEM("ImgNews").src = "WebSite/Image/Ico/MailNull.png";
            }
            $MEM("ImgNews").onclick = function () {
                RedirectFrame('WebSite/Branch/FunctionCenter/MyNews/Frame.html');
            }
            //载入用户基本信息
            $MEM("ImgUser").title = "用户:" + Data.UserName;
            $MEM("ImgUser").title += "\nIP地址:" + Data.IPAddress;
            $MEM("ImgUser").title += "\n时间:" + $MD.Date(Data.LoginTime).toFormatString("yyyy/mm/dd hh:MM:ss");
            $MEM("ImgUser").title += "\n邮箱:" + Data.Email;
        }
    });
}
/*打开子界面*/
RedirectFrame = function (url) {
    if (url.length > 0) {
        $MEM("PageFrame").src = url;
    }
}

